<%
@json_recommendations = @document.json_recommendations(@limit, params[:order] || "mixed", true, params[:omit_feeds] || nil) 
if !@json_recommendations.nil? 
@direct_link_text = params[:direct_link_text] || l(:direct_link)
%>
var catalog_page = <%= !@document.direct_link.nil? and @uri == @document.permalink %>;
var document_host = '<%= @host %>';
var recs = <%= @json_recommendations %>;
var app = "http://www.oerrecommender.org/"; 
<% if @details == true -%>
function truncate(text, length) {
	nEnd = text.indexOf(" ", 200);
	if (nEnd < 200) return text;
	else return text.substring(0, nEnd) + " ...";
}
var asMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function format_date(published_at) {
	date = new Date();
	date.setTime(Date.parse(published_at));
	return date.getDate() + " " + asMonths[date.getMonth()] + " " + date.getUTCFullYear();
}
<% end %>
document.write('<div class="oer_recommender_container">');
<% if params[:title] %>document.write('<div class="oer_recommender_title"><%= l(:gm_title) %></div>');<% end %>
document.write('<div class="oer_recommender_list">');
for(nRec = 0; nRec < recs.length; nRec++) {
	r = recs[nRec];
	metadata_link = catalog_page && document_host == r.uri.substring(0, document_host.length);
	direct_link = metadata_link && r.direct_link;
	document.write('<p class="oer_recommender_item">');
	document.write('<a class="oer_recommender_recommendation_link" href="' + app + 'r?id=' + r.id + (metadata_link ? "&target=metadata" : "") + '">' + r.title + ' (' + r.collection + ')</a>');
	if (direct_link) document.write(' <a class="oer_recommender_direct_link" href="' + app + 'r?id=' + r.id + '&target=direct_link"><%= @direct_link_text %></a>');
<% if @details == true -%>
	document.write(' <span class="oer_recommender_published_at">(' + format_date(r.published_at) + ')</span>');
	document.write(' <span class="oer_recommender_relevance_score"><%= l(:relevance)%>: ' + Math.round(r.relevance*100)/100 + '</span>');
	document.write('<br/><span class="oer_recommender_description">' + truncate(r.description) + '</span>');
	document.write('<br/><span class="oer_recommender_uri">' + r.uri + '</span>');
<% end -%>	
	document.write('</a></p>');
}
document.write('</div>');	
<% if params[:more_link] %>document.write('<div class="oer_recommender_more_link"><a href="' + app + 'documents/<%= @document.id %>"><%= l(:gm_more_prompt) %></a></div>');<% end %>	
document.write('</div>');	
<% end %>
